import QtQuick
import QtQuick.Controls

Rectangle {
    id: skill

    // 使用技能
    signal using_skill(string skillIndex)

    /* 更新技能
      skillIndex: int // 0, 1, 2, 3
      newSkill:string
      ex: update_skill(1, "火球")
    */
    function update_skill(skillIndex, newSkill){
        if(skillIndex < 0 || skillIndex >= listModel.count) {
            return 1
        }
        var item = listModel.get(skillIndex)

        listModel.setProperty(skillIndex, "name", newSkill)
        return 0
    }


    // 主角攻击交互界面
    /*
        name 是技能名
        index 是技能序号
    */
    ListModel {
        id: listModel
        ListElement{name: "技能一"}
        ListElement{name: "技能二"}
        ListElement{name: "技能三"}
        ListElement{name: "技能四"}
    }

    ListView {
        id: listView
        model: listModel
        width: parent.width
        height: parent.height

        delegate: Rectangle{
            width: listView.width
            height: listView.height / 4
            color: index % 2 === 0? "#333": "#444"

            Text {
                text: name
                color: "white"
                font.pixelSize: 16
                anchors.centerIn: parent
            }

            MouseArea {
                anchors.fill: parent
                onClicked: {
                    using_skill(name)
                }

                onReleased: {
                    parent.color= index % 2 === 0? "#333": "#444"
                }

                onPressed: {
                    parent.color = "#222"
                }
            }
        }

    }
}
